package com.lagou.mr.sort;

import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class NumberSortReducer extends Reducer<NumberSortBean, NullWritable,
        NullWritable, NumberSortBean> {
    long sortNum = 1;
    @Override
    protected void reduce(NumberSortBean key, Iterable<NullWritable> values, Context context) throws IOException, InterruptedException {
        //因为key已排好序，排序号累加写入即可
        for(NullWritable v:values){
            key.setSortNum(sortNum);
            sortNum++;
            context.write(v,key);
        }
    }
}
